package ca.utoronto.utm.csc301.euchre.gamemanager;

import java.lang.reflect.InvocationTargetException;

import ca.utoronto.utm.csc301.euchre.player.Player;
import ca.utoronto.utm.csc301.euchre.player.PlayerFactory;

/**
 * The main driver program for the Euchre game.
 *
 * @author Game Manager Team 2
 */
public class Euchre {
	private static GameManager manager;	
	private static Player one, two, three, four;
	
	/**
	 * Entry point of the program.
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("Euchre Game Manager");
		
		for (int i = 0; i < 10; i++) {
			Euchre.executeGame();
		}
	}

	/**
	 * Execute one instance of a euchre game. 
	 */
	public static void executeGame() {
		try {
			manager = new EuchreManager();
			
			one = PlayerFactory.createPlayer("ca.utoronto.utm.csc301.euchre.player.PlayerD", 0, manager);
			two = PlayerFactory.createPlayer("ca.utoronto.utm.csc301.euchre.player.PlayerD", 2, manager);
			three = PlayerFactory.createPlayer("ca.utoronto.utm.csc301.euchre.player.PlayerD", 1, manager);
			four = PlayerFactory.createPlayer("ca.utoronto.utm.csc301.euchre.player.PlayerD", 3, manager);
			
			manager.setPlayers(one, two, three, four);
			manager.startGame();
		} catch (IllegalPlayException e1) {
			System.err.println(e1.getMessage());
			e1.printStackTrace();
			System.exit(1);
		} catch (IllegalArgumentException e1) {
			e1.printStackTrace();
			System.exit(2);
		} catch (SecurityException e1) {
			e1.printStackTrace();
			System.exit(3);
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
			System.exit(4);
		} catch (InstantiationException e1) {
			e1.printStackTrace();
			System.exit(5);
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
			System.exit(6);
		} catch (InvocationTargetException e1) {
			e1.printStackTrace();
			System.exit(7);
		} catch (NoSuchMethodException e1) {
			e1.printStackTrace();
			System.exit(8);
		}
	}
}
